package Java2Test.HashMap;

import java.util.*;

public class HashMapTest2 {
    public static void main(String[] args) {
        String[] arr = {"A", "B", "C", "D"};

        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();
        for (int i = 0; i < 80; i++) {
            int index = r.nextInt(arr.length);
            list.add(arr[index]);
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        Map<String, Integer> m = new HashMap<>();
        for (String name : list) {
            if (m.containsKey(name)){
                Integer count = m.get(name);
                count++;
                m.put(name, count);
            }else {
                m.put(name, 1);
            }
        }

        System.out.println(m);

        int max = 0;
        Set<Map.Entry<String, Integer>> entries = m.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            Integer value = entry.getValue();
            if (value > max){
                max = value;
            }
        }

        for (Map.Entry<String, Integer> entry : entries) {
            if (max == entry.getValue()){
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
        }
    }
}
